'''
Description: 
Author: Zilu
Date: 2021-11-04 14:05:17
Version: 
LastEditTime: 2021-11-04 14:14:06
LastEditors: Zilu
'''

# python的字符串、list、dict都是可迭代对象
from typing import Collection


d = {'a':1, 'b':2, 'c':3}
for key in d:
    print(key)

for value in d.values():
    print(value)

for k,v in d.items():
    print(k, v)

# 用collection.abc中的Iterable类可以判断对象是否可迭代
from collections.abc import Iterable
isinstance('abc', Iterable)
isinstance(123, Iterable)

# python内置了enumerate函数将list变成索引-元素对
for i,v in enumerate([3,4,5]):
    print(i,v)
    
# 练习：用迭代找出list中的最大最小值
def findMinAndMax(L):
    if len(L)==0:
        return None, None
    min = L[0]
    max = L[0]
    for num in L:
        if min > num:
            min = num
        if max < num:
            max = num
    return min, max

